<!-- 概况-访客会员-会员管理 -- 许达 -- 2017年9月11日 星期一 -->
<template>
  <div >
    <!-- 查询条件：昵称、电话、创建时间 -->
<!--    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;height:46px">-->
<!--      <el-form :inline="true">-->
<!--        <el-form-item v-if="openIdIsShow">-->
<!--          <el-input v-model="queryOpenIdName" size="small" placeholder="微信号"  style="width: 130px;vertical-align: top"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item>-->
<!--          <el-input v-model="queryNickName" size="small" placeholder="昵称"  style="width: 130px;vertical-align: top"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item>-->
<!--          <el-input v-model="queryPhone" size="small" placeholder="电话"   style="width: 130px;vertical-align: top"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item>-->
<!--          <el-date-picker v-model="queryStartCreateTime" type="date" placeholder="创建时间开始" size="small" style="width: 150px;vertical-align: top"></el-date-picker>-->
<!--        </el-form-item>-->
<!--        <el-form-item>-->
<!--          <el-date-picker v-model="queryEndCreateTime" type="date" placeholder="创建时间结束"  size="small" style="width: 150px;vertical-align: top"></el-date-picker>-->
<!--        </el-form-item>-->
<!--        <el-form-item>-->
<!--          <el-button type="primary" v-on:click="search" size="small" style="line-height:14px;vertical-align: top">查询</el-button>-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--    </el-col>-->
    <!--列表-->
    <el-table :data="memberList" v-loading="listLoading" @selection-change="selsChange" border style="width: 100%; font-size: 12px;" row-class-name="tabRow" tooltipEffect="light">
      <!--<el-table-column type="selection"></el-table-column>-->
      <el-table-column align="center" prop="userName" label="昵称" show-overflow-tooltip></el-table-column>
      <el-table-column align="center" prop="crtTime" label="打卡时间"></el-table-column>
<!--      <el-table-column align="center" :formatter="createTimeStr" label="打卡时间" ></el-table-column>-->
    </el-table>
    <el-col :span="24" class="toolbar" style="margin-top: 15px;" v-show="!listLoading">
      <el-pagination id="pagination" layout="total, sizes, prev, pager, next, jumper" :page-sizes="[10, 20, 30]" @size-change="handleSizeChange"
                     @current-change="handleCurrentChange" :page-size="pageSize" :current-page="page" :total="total" style="float:right;">
      </el-pagination>
    </el-col>

  </div>
</template>

<script type="text/ecmascript-6">
  import {resetBreads, sessionOut} from '../../smartlight/common/js/util.js'
  export default {
    data () {
      return {
        memberType: this.$route.query.type,
        menuType: 'member',
        menuIndex: 0,
        memberList: [],
        total: 0,
        page: 1,
        pageSize: 10,
        queryNickName: '',
        queryPhone: '',
        queryStartCreateTime: '',
        queryEndCreateTime: '',
//        queryCompanyName: '',
//        queryShopName: '',
        queryCompanyId: '',
        queryShopId: '',
        queryOpenIdName: '',
        id: 0,
        sels: [], // 列表选中列
        listLoading: false,
        addFlag: '',
        showAdd: false,
        addLoading: false,
        loginType: 0,
        shopId: '',
        member: {
          nickName: '',
          gender: '',
          province: '',
          city: '',
          country: '',
          unionId: '',
          visitCount: '',
          createTime: ''
        },
        opType: 'detail',
        dialogTitle: '会员信息详情',
        companNnameIsShow: false,
        shopNameIsShow: false,
        openIdIsShow: false
      }
    },
    watch: {// 针对访问相同文件不同参数
      $route () {
        this.initMemberList()
      }
    },
    methods: {
      s1 (id) {
        this.queryCompanyId = id
      },
      s2 (id) {
        this.queryShopId = id
      },
      // 性别转换
      formatGender (row, column) {
        if (row.gender === 0) {
          return '未知'
        } else if (row.gender === 1) {
          return '男'
        } else if (row.gender === 2) {
          return '女'
        } else {
          return ''
        }
//        return row.sex === 1 ? '男' : '女'
      },
      // 初始化查询条件
      initSearchParam () {
        var stype = this.$route.query.sys
        if (stype) {
          this.companNnameIsShow = true
          this.shopNameIsShow = true
          this.openIdIsShow = true
        }
      },
      checkIfLogin () { // 判断是否登录超时
        var user = sessionStorage.getItem('user')
        if (!user) {
          this.$alert('登录超时，请重新登录！', ' ', {
            type: 'warning'
          }).then(() => {
            this.$router.push({path: '/login'})
            sessionStorage.clear()
          })
        } else {
          return true
        }
      },
      // 分页插件查询方法-条数
      handleSizeChange (val) {
        this.pageSize = val
        this.initMemberList()
      },
      // 分页插件查询方法-页数
      handleCurrentChange (val) {
        this.page = val
        this.currentPage = val
        this.initMemberList()
      },
      // 初始化分页查询会员表
      initMemberList () {
        var user = sessionStorage.getItem('user')
        if (user) {
          user = JSON.parse(user)
          this.loginType = user.type
        }
        this.listLoading = true
        var dealStartTime = this.dealTimeStr(this.queryStartCreateTime)
        var dealEndTime = this.dealTimeStr(this.queryEndCreateTime)
        var para = {
          type: this.loginType,
          pageNumber: this.page,
          pageSize: this.pageSize,
          nickName: this.queryNickName,
          phone: this.queryPhone,
          startTime: dealStartTime,
          endTime: dealEndTime,
          memberType: this.$route.query.type,
          sysType: this.$route.query.sys,
          companyId: this.queryCompanyId,
          openId: this.queryOpenIdName
        }
        // this.$http.post('/smartLight/web/member/getPageList.htm', para).then(response => {
        //   var resBody = response.body
        //   this.listLoading = false
        //   if (resBody.isSuccess === 0) {
        //     this.total = resBody.result.totalElements
        //     this.memberList = resBody.result.content
        //   } else if (resBody.isSuccess === 2) {
        //     sessionOut(this) // session超时处理
        //   } else {
        //     this.$message({
        //       showClose: true,
        //       message: resBody.errorMsg,
        //       type: 'error'
        //     })
        //   }
        // })
        this.$ajax.post('/api/baseSignBill/getPage', para,  (data)=> {
          this.listLoading = false
          var data = JSON.parse(data)
          console.log(data)
          if (data.code == 1) {
            this.total = data.count
            this.memberList = data.data
          } else {
            this.$message.error(data.msg)
          }
        })
      },
      // 【查询】
      search () {
        if (!this.checkIfLogin()) {
          return
        }
        this.initMemberList()
      },
      selsChange: function (sels) {
        this.sels = sels
      },
      // 时间格式化
      createTimeStr (row, column) {
        var d = new Date(row.createTime)
        var year = d.getFullYear()
        var month = d.getMonth() + 1
        if (month < 10) {
          month = '0' + month
        }
        var date = d.getDate()
        if (date < 10) {
          date = '0' + date
        }
        var hh = d.getHours()
        if (hh < 10) {
          hh = '0' + hh
        }
        var mm = d.getMinutes()
        if (mm < 10) {
          mm = '0' + mm
        }
        var ss = d.getSeconds()
        if (ss < 10) {
          ss = '0' + ss
        }
        return year + '-' + month + '-' + date + ' ' + hh + ':' + mm + ':' + ss
      },
      // 查询时间格式化
      dealTimeStr (ob) {
        if (!ob) {
          return ''
        } else {
          var d = ob
          var year = d.getFullYear()
          var month = d.getMonth() + 1
          if (month < 10) {
            month = '0' + month
          }
          var date = d.getDate()
          if (date < 10) {
            date = '0' + date
          }
          var hh = d.getHours()
          if (hh < 10) {
            hh = '0' + hh
          }
          var mm = d.getMinutes()
          if (mm < 10) {
            mm = '0' + mm
          }
          var ss = d.getSeconds()
          if (ss < 10) {
            ss = '0' + ss
          }
          return year + '-' + month + '-' + date
        }
      }
    },
    mounted () {
      this.initMemberList()
      this.initSearchParam()
      resetBreads(this)
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  .is-light
    max-width: 600px;
  .tabRow
    font-size: 12px;
  .button-align
    float: right;
  .el-dialog--small
    width: 37% ;
  .prompt
    color: #ff4949
    line-height: 10px !important;
    display: block;

  #formheight
    margin: 14px 0;
    height: 38px;
    .el-form-item__content
      height: 30px;
      .el-form-item__error
        margin-top:3px
    .el-input
      height: 30px;
      .el-input__inner
        height: 30px;

  .borderStyle
    .el-input .el-input__inner {
      border-color: #ff4949 !important;
    }
  .cell
    padding-left: 0px !important
    padding-right 0px !important
    overflow: hidden !important
    text-overflow: ellipsis !important
    white-space: nowrap !important
    .el-checkbox {
      padding-left: 15px !important
    }
  #pagination
    background-color: transparent
    .el-input__inner
      width: 120px
</style>
